package test;

import static org.junit.Assert.*;

import movement.Location;

import org.junit.Before;
import org.junit.Test;

import dispatch.DispatchCenter;
import emergency.*;

public class testEmergencyBoard {

	private DispatchCenter center;
	private EmergencyBoard board;

	@Test(expected = IllegalArgumentException.class)
	public void createEmergencyBoardNullDispatchCenter() {
		@SuppressWarnings("unused")
		EmergencyBoard emb = new EmergencyBoard(null);
	}
	
	@SuppressWarnings("unused")
	@Test
	public void getEmergenciesFromType(){
		Location l = new Location(10, 10, "Jap");
		Emergency em1 = new PublicDisturbance(l, Severity.NORMAL, center, 1);
		Emergency em2 = new PublicDisturbance(l, Severity.NORMAL, center, 2);
		Emergency em3 = new Robbery(l, Severity.NORMAL, center, true,false);
		
		assertEquals(center.getEmergencyboard().getEmergenciesFromType("PublicDisturbance").size(), 2);
		assertEquals(center.getEmergencyboard().getEmergenciesFromType("Robbery").size(), 1);
		assertEquals(center.getEmergencyboard().getEmergenciesFromType("Fire").size(), 0);
		assertEquals(center.getEmergencyboard().getEmergenciesFromType("TrafficAccident").size(), 0);
	}
	
	@Test
	public void getEmergencyState(){
		Location l = new Location(10, 10, "Jap");
		Emergency em1 = new PublicDisturbance(l, Severity.NORMAL, center, 1);
		Emergency em2 = new PublicDisturbance(l, Severity.NORMAL, center, 2);
		Emergency em3 = new Robbery(l, Severity.NORMAL, center, true,false);
		
		assertTrue(center.getEmergencyboard().getEmergenciesRecorded().contains(em1));
		assertTrue(center.getEmergencyboard().getEmergenciesRecorded().contains(em2));
		assertTrue(center.getEmergencyboard().getEmergenciesRecorded().contains(em3));
		
		assertEquals(center.getEmergencyboard().getEmergenciesCancelled().size(),0);
		assertEquals(center.getEmergencyboard().getEmergenciesCompleted().size(),0);
		assertEquals(center.getEmergencyboard().getEmergenciesInProgress().size(),0);
	}

	@Before
	public void setUp() throws Exception {
		center = new DispatchCenter("DC 1", new Location(45, 45,
		"DC 1 - Location"), new Location(60, 60, "GarageLocation"));
		board = new EmergencyBoard(center);
	}

	@Test
	public void testAddEmergency() {
		Location emLocation = new Location(20, 20, "Test");
		Emergency em1 = new PublicDisturbance(emLocation, Severity.BENIGN,
				center, 3);
		Emergency em2 = new Robbery(emLocation, Severity.SERIOUS, center,
				false, false);
		assertEquals(board.getEmergencies().size(), 0);
		board.addEmergency(em1);
		assertEquals(board.getEmergencies().size(), 1);
		board.addEmergency(em2);
		assertEquals(board.getEmergencies().size(), 2);
	}

	@Test(expected = IllegalArgumentException.class)
	public void testAddInvalidEmergencyDispatchcenterNull() {
		Emergency em1 = new PublicDisturbance(new Location(20, 20, "Test"),
				Severity.SERIOUS, null, 3);
		board.addEmergency(em1);
	}

	@Test(expected = IllegalArgumentException.class)
	public void testAddInvalidEmergencyLocationNull() {
		Emergency em1 = new PublicDisturbance(null, Severity.BENIGN, center, 3);
		board.addEmergency(em1);
	}

	@Test(expected = IllegalArgumentException.class)
	public void testAddInvalidEmergencySeverityNull() {
		Emergency em1 = new PublicDisturbance(new Location(20, 20, "Test"),
				null, center, 3);
		board.addEmergency(em1);
	}
	
	@Test
	public void testConstructor(){
		assertEquals(board.getDispatchcenter(), center);
		assertEquals(board.getEmergencies().size(), 0);
	}
	
	@Test
	public void testGettersAndSetters() {
		assertEquals(board.getDispatchcenter(), center);
		assertNotNull(board.getEmergencies());
		assertEquals(board.getEmergencies().size(), 0);
	}


}